<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //1.map递归
        function flatten(arr) {
            let res = [];
            arr.map(item => {
                if(Array.isArray(item)){
                    // 是数组，就递归拼接
                    res = res.concat(flatten(item))
                }else
                res = res.concat(item)
            })
            return res
        }
        let arr = [1,[2,3,[4,5]],6]
        console.log(flatten(arr));

        //2.reduce(累加器)递归
        function flatten1(arr){
            return arr.reduce((result,item) => {
                return result.concat(Array.isArray(item) ? flatten1(item) : item)
            },[])
        }
        console.log(flatten1(arr));
        
    </script>
</head>
<body>
    
</body>
</html>